package py.com.fms.fms.session.maintenances;

//External classes imports 
//Java Classes
import java.text.ParseException;
import java.util.*;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Credentials;
import org.jboss.seam.security.Identity;

import py.com.fms.exception.CommonException;
import py.com.fms.session.ParamHolder;
import py.com.fms.session.ServiceSqlMap;
import py.com.fms.session.WithinHolder;
import py.com.fms.utilities.ConvertAssistant;
import py.com.fms.utilities.DateAssistant;
import py.com.fms.persistence.services.StatusTypeHandlerCallback;


import py.com.fms.fms.bean.CurrencyBean;
import py.com.fms.fms.bean.CountryBean;
import py.com.fms.fms.bean.PersonBean;
import py.com.fms.fms.bean.PersonManagerBean;
import py.com.fms.fms.bean.PersonAddressBean;
import py.com.fms.fms.bean.PersonDocumentBean;
import py.com.fms.fms.bean.PersonPhoneBean;
import py.com.fms.fms.bean.RefDetBean;
import py.com.fms.fms.bean.UsersBean;

import py.com.fms.fms.persistence.services.PersonServices;
import py.com.fms.fms.persistence.services.CountryServices;
import py.com.fms.fms.persistence.services.RefServices;
import py.com.fms.fms.persistence.services.UsersServices;


@SuppressWarnings("unused")
@Name("editPerson")
@Scope(ScopeType.SESSION)
public class EditPerson {
	
	private FacesMessages facesMessages;
	@Logger
	private Log log;
	@In("#{serviceSqlMap}")
	private ServiceSqlMap sqlMap;
	private String initVar;
	private Date today = null;
	
	// Task Attendees Attributes 
	@In("#{withinHolder}")
	private WithinHolder aid;
	@In("#{paramHolder}")
	private ParamHolder param;
	@In("#{convertAssist}")
	private ConvertAssistant convert;
	private DateAssistant dateAssist;
	@In Credentials credentials;
	@In Identity identity;
	private UsersBean user;
	
	
	// Attribute used for saving and deleting
	private PersonBean person;
	private PersonBean personUpd;
	private PersonManagerBean personManager;
	private PersonAddressBean personAddr;
	private PersonDocumentBean personDoc;
	private PersonPhoneBean personPhone;
	
	
	// Services
	private PersonServices prSrv;
	private CountryServices cnSrv;
	private UsersServices usSrv;
	private RefServices rnSrv;

	
	// Attribute used for editing or updating
	private PersonBean editPerson;
	private PersonAddressBean editAddr;
	private PersonDocumentBean editDoc;
	private PersonPhoneBean editPhone;
	private PersonBean personToAdd;
	private PersonAddressBean addrToAdd;
	private PersonDocumentBean docToAdd;
	private PersonPhoneBean phoneToAdd;

	// Collection of PersonBean
	private Collection<PersonBean> allPersons;
	private Collection<PersonAddressBean> allPersonAddress;
	private Collection<PersonDocumentBean> allPersonDoc;
	private Collection<PersonPhoneBean> allPersonPhone;
	
	// ||GRID COLLECTIONS||
	private List<PersonAddressBean> personAddrCollection;
	private List<PersonDocumentBean> personDocCollection;
	private List<PersonPhoneBean> personPhoneCollection;
	
	private List<PersonAddressBean> personAddrToAdd;
	private List<PersonDocumentBean> personDocToAdd;
	private List<PersonPhoneBean> personPhoneToAdd;
	
	// ||REMOVE COLLECTIONS||

	
	// ||SEARCH COLLECTIONS||
	private List<PersonBean> personSearch;
	private List<PersonAddressBean> personAddrSearch;
	private List<PersonDocumentBean> personDocSearch;
	private List<PersonPhoneBean> personPhoneSearch;

	
	
	//	Necessary Attributes;
	
	//Person
	private Long personId;
	private long personEnt;
	private String personCod;
	private PersonBean personName;
	
	private Long addrTypeId;
	private Long docTypeId;
	private Long phoneTypeId;
	private Long sectorId;
	
	private String addrType;
	private String docType;
	private String phoneType;
	private String sectorEco;
	
	
	//Checks
	private boolean checkAddr;
	private boolean checkDoc;
	private boolean checkPhone;
	
	//Delete Attributes
	
	//	Operations
	// 	Selections
	//		newPerson
	//		updPerson
	//		addPerson
	
	private String operation = "newPerson";
	private String selectedTab = "newPerson";
	
	private String updTab = "updPersonSub";
	private String selectedTabUpd = "updPersonSub";
	
	
	/**
	 * [[[[[[[[[[[[ Methods ]]]]]]]]]]]] 
	 * [[[[[[[[[[-------------]]]]]]]]]]
	 * @throws CommonException 
	 */

	public void initData() throws CommonException {

		System.out.println("initVar = " + this.getInitVar());

		if ("S".equals(this.getInitVar())) {
			
			this.initBeans();
			this.initServices();
			this.initAssistants();
			this.initCollections();
			this.loadAllPerson();
			this.loadUserData();
			this.loadRefData();
			this.loadParams();
			System.out.println("Operacion: " + operation);
			if(operation.equals("updPerson")){
				this.loadAllPersonAddr();
				this.loadAllPersonDoc();
				this.loadAllPersonPhone();				

			}
			
//			this.setEditMode(false);
//			this.loadGrid();
//			this.fillList();
		
			
		}
		this.setInitVar(null);
		System.out.println("OUT");
				
	}
	
	// INITIALIZING --------------------]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
	
	public void loadParams() throws CommonException{
		this.param.initData();
		this.param.loadParams();
	}
	
	private void loadUserData() throws CommonException{
		if(credentials != null){
			System.out.println("Credenciales Encontradas");
			this.getUser().setUserName(credentials.getUsername());
			System.out.println("User Name: " + this.getUser().getUserName());
			user = usSrv.getUserDataByName(this.getUser().getUserName());
			this.setUser(user);
			System.out.println("User: " + this.getUser());
		}else{	
			System.out.println("Credenciales Nulas");
		}
	}
	
	private void loadRefData() throws CommonException{
		this.addrType = "TIPDIREC";
//		this.setAddrTypeId(rnSrv.getIdHeadByDesc(addrType.toUpperCase()));
//		System.out.println("REf:" + this.getAddrTypeId());
		
		this.docType = "TIPDOCU";
//		this.setDocTypeId(rnSrv.getIdHeadByDesc(docType.toUpperCase()));
//		System.out.println("REf:" + this.getDocTypeId());
		
		this.phoneType = "TIPTELEF";
//		this.setPhoneTypeId(rnSrv.getIdHeadByDesc(phoneType.toUpperCase()));
//		System.out.println("REf:" + this.getPhoneTypeId());
		
		this.sectorEco = "SECTORECO";
//		this.setSectorId(rnSrv.getIdHeadByDesc(sector.toUpperCase()));
//		System.out.println("REf:" + this.getSectorId());
	}
	
	public void initBeans(){
		if (personManager == null){
			personManager = new PersonManagerBean();
			personManager.getPerson().setStatus(true);
		}
		
		if (person == null){
			person = new PersonBean();
		}
		
		if (personAddr == null){
			personAddr = new PersonAddressBean();
			personAddr.setStatus(true);
		}
		
		if (personDoc == null){
			personDoc = new PersonDocumentBean();
			personDoc.setStatus(true);
		}
		
		if (personPhone == null){
			personPhone = new PersonPhoneBean();
			personPhone.setStatus(true);
		}
		
		if (personToAdd == null){
			personToAdd = new PersonBean();
		}
		
		if (addrToAdd == null){
			addrToAdd = new PersonAddressBean();
			addrToAdd.setStatus(true);
		}
		
		if (docToAdd == null){
			docToAdd = new PersonDocumentBean();
			docToAdd.setStatus(true);
		}
		
		if (phoneToAdd == null){
			phoneToAdd = new PersonPhoneBean();
			phoneToAdd.setStatus(true);
		}

//		if(operation.equals("updPerson")){
			if (personUpd == null){
				personUpd = new PersonBean();
			}
			if (editPerson == null){
				editPerson = new PersonBean();
			}
			
			if (editAddr == null){
				editAddr = new PersonAddressBean();
			}
			
			if (editDoc == null){
				editDoc = new PersonDocumentBean();
			}
			
			if (editPhone == null){
				editPhone = new PersonPhoneBean();
			}
//		}
			if (user == null){
				user = new UsersBean();
			}
			
		
		
	
		
	}
	
	public void initServices() throws CommonException{
		
		if (prSrv == null){
			prSrv = new PersonServices(this.sqlMap.getConfig());
		}
		
		if (cnSrv == null){
			cnSrv = new CountryServices(this.sqlMap.getConfig());
		}
		
		if (usSrv == null){
			usSrv = new UsersServices(this.sqlMap.getConfig());
		}
		
		if (rnSrv == null){
			rnSrv = new RefServices(this.sqlMap.getConfig());
		}
			
		
	}
	
	public void initAssistants(){
		
		if(aid == null){
			aid = new WithinHolder();
		}
		
		if(param == null){
			param = new ParamHolder();
		}
		
		if(convert == null){
			convert = new ConvertAssistant();
		}
		
		if(dateAssist == null){
			dateAssist = new DateAssistant();
		}
		
	}
	
	public void initCollections(){
		if(allPersons == null){
			allPersons = new ArrayList<PersonBean>();
		}
		if(allPersonAddress == null){
			allPersonAddress = new ArrayList<PersonAddressBean>();
		}
		if(allPersonDoc == null){
			allPersonDoc = new ArrayList<PersonDocumentBean>();
		}
		if(allPersonPhone == null){
			allPersonPhone = new ArrayList<PersonPhoneBean>();
		}
		if(personAddrCollection == null){
			personAddrCollection = new ArrayList<PersonAddressBean>();
		}
		if(personDocCollection == null){
			personDocCollection = new ArrayList<PersonDocumentBean>();
		}
		if(personPhoneCollection == null){
			personPhoneCollection = new ArrayList<PersonPhoneBean>();
		}

		
		if(operation.equals("addPerson")){
			if(personAddrToAdd == null){
				personAddrToAdd = new ArrayList<PersonAddressBean>();
			}
			if(personDocToAdd == null){
				personDocToAdd = new ArrayList<PersonDocumentBean>();
			}
			if(personPhoneToAdd == null){
				personPhoneToAdd = new ArrayList<PersonPhoneBean>();
			}
		}

		if(operation.equals("updPerson")){
			if(personSearch == null){
				personSearch = new ArrayList<PersonBean>();
			}
			if(personAddrSearch == null){
				personAddrSearch = new ArrayList<PersonAddressBean>();
			}
			
			if(personDocSearch == null){
				personDocSearch = new ArrayList<PersonDocumentBean>();
			}
			
			if(personPhoneSearch == null){
				personPhoneSearch = new ArrayList<PersonPhoneBean>();
			}
		}
	

	}
	
	public void cleanData(){
		
			personManager = null;
			person = null;
			personAddr = null;
			personDoc = null;
			personPhone = null;
			personToAdd = null;
			addrToAdd = null;
			docToAdd = null;
			phoneToAdd = null;
			

			prSrv = null;
			cnSrv = null;

			aid = null;
			convert = null;
			dateAssist = null;
			

			allPersons = null;
			allPersonAddress = null;
			allPersonDoc = null;
			allPersonPhone = null;
			personAddrCollection = null;
			personDocCollection = null;
			personPhoneCollection = null;

			personAddrToAdd = null;
			personDocToAdd = null;
			personPhoneToAdd = null;
			personSearch = null;
			personAddrSearch = null;
			personDocSearch = null;
			personPhoneSearch = null;


	}
	

	
	public Boolean checkAddrDfl(){
		Boolean result = false;
		Iterator<PersonAddressBean> it = personAddrCollection.iterator();
		PersonAddressBean next = null;
		while(it.hasNext()){
			next = it.next();
			if (Boolean.TRUE.equals(next.getIsDefault())){
				result = true;
				break;
			}else{
				result = false;
			}
		}
		System.out.println("result: " + result);
		return result;
	}
	
	public Boolean checkDocDfl(){
		Boolean result = false;
		Iterator<PersonDocumentBean> it = personDocCollection.iterator();
		PersonDocumentBean next = null;
		while(it.hasNext()){
			next = it.next();
			if (Boolean.TRUE.equals(next.getIsDefault())) { //(next.isDefault() == true){
				result = true;
				break;
			}else{
				result = false;
			}
		}
		System.out.println("result: " + result);
		return result;
	}
	
	public Boolean checkPhoneDfl(){
		Boolean result = false;
		Iterator<PersonPhoneBean> it = personPhoneCollection.iterator();
		PersonPhoneBean next = null;
		while(it.hasNext()){
			next = it.next();
			if (Boolean.TRUE.equals(next.getIsDefault())) {
				result = true;
				break;
			}else{
				result = false;
			}
		}
		System.out.println("result: " + result);
		return result;
	}
	
	public Boolean checkAddrAddDfl(){
		Boolean result = false;
		if(personAddrToAdd.isEmpty()){
			for(PersonAddressBean bean : this.getAllPersonAddress()){
				if (Boolean.TRUE.equals(bean.getIsDefault())) {
					result = true;
					break;
				}else{
					result = false;
				}
			}
		}else{
			for(PersonAddressBean bean : this.getPersonAddrToAdd()){
				if (Boolean.TRUE.equals(bean.getIsDefault())) {
					result = true;
					break;
				}else{
					for(PersonAddressBean addr : this.getAllPersonAddress()){
						if (Boolean.TRUE.equals(addr.getIsDefault())) {
							result = true;
							break;
						}else{
							result = false;
						}
					}
				}
			}
		}
		
		System.out.println("result: " + result);
		return result;
	}
	
	public Boolean checkDocAddDfl(){
		Boolean result = false;
		if(personDocToAdd.isEmpty()){
			for(PersonDocumentBean bean : this.getAllPersonDoc()){
				if (Boolean.TRUE.equals(bean.getIsDefault())) {
					result = true;
					break;
				}else{
					result = false;
				}
			}
		}else{
			for(PersonDocumentBean bean : this.getPersonDocToAdd()){
				if (Boolean.TRUE.equals(bean.getIsDefault())) {
					result = true;
					break;
				}else{
					for(PersonDocumentBean doc : this.getAllPersonDoc()){
						if (Boolean.TRUE.equals(doc.getIsDefault())) {
							result = true;
							break;
						}else{
							result = false;
						}
					}
				}
			}
		}
		
		System.out.println("result: " + result);
		return result;
	}
	
	public Boolean checkPhoneAddDfl(){
		Boolean result = false;
		if(personPhoneToAdd.isEmpty()){
			for(PersonPhoneBean bean : this.getAllPersonPhone()){
				if (Boolean.TRUE.equals(bean.getIsDefault())) {
					result = true;
					break;
				}else{
					result = false;
				}
			}
		}else{
			for(PersonPhoneBean bean : this.getPersonPhoneToAdd()){
				if (Boolean.TRUE.equals(bean.getIsDefault())) {
					result = true;
					break;
				}else{
					for(PersonPhoneBean phone : this.getAllPersonPhone()){
						if (Boolean.TRUE.equals(phone.getIsDefault())) {
							result = true;
							break;
						}else{
							result = false;
						}
					}
				}
			}
		}
		
		System.out.println("result: " + result);
		return result;
	}
	
	// Method used for operation changing
	public void changeOperation (ActionEvent event){
		selectedTab = operation;
		this.setInitVar("S");
	}
	
	public void changeUpdTab(String param){
		selectedTabUpd = param;
		this.setInitVar("S");
	}
	
	// Used to load a collection with all data
	private void loadAllPerson() {
		try {
			this.setAllPersons(prSrv.getAllPersons());
			
		} catch (CommonException e) {
			e.printStackTrace();
		}
	}
	
	private void loadAllPersonAddr() {
		try {
			this.setAllPersonAddress(prSrv.getAllPersonAddress());
			
		} catch (CommonException e) {
			e.printStackTrace();
		}
	}
	
	private void loadAllPersonDoc() {
		try {
			this.setAllPersonDoc(prSrv.getAllPersonDoc());
			
		} catch (CommonException e) {
			e.printStackTrace();
		}
	}
	
	private void loadAllPersonPhone() {
		try {
			this.setAllPersonPhone(prSrv.getAllPersonPhone());
			
		} catch (CommonException e) {
			e.printStackTrace();
		}
	}
	
	public void loadPersonDetails(){
		try {
			System.out.println("Loading Person Details");
			this.setAllPersonAddress(prSrv.getPersonsAddress(this.getPersonToAdd().getId()));
			this.setAllPersonDoc(prSrv.getPersonsDoc(this.getPersonToAdd().getId()));
			this.setAllPersonPhone(prSrv.getPersonsPhone(this.getPersonToAdd().getId()));
		} catch (CommonException e) {
			e.printStackTrace();
		}
		
	}
	
	// METHODS FOR NEW PERSON OPERATION --------------------]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
	
	// Methods for addresses handle ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
	
	public void fillAddrList(){
		System.out.println("Filling address list");
		if (this.getPersonAddr() == null){
			System.out.println("Entity null");
		}else{
			
			personAddrCollection.add(this.getPersonAddr());
			
			System.out.println(this.getPersonAddr().getAddress());
			System.out.println("------------------------");
		}
		this.checkAddr = false;
		this.setInitVar("S");
		this.setPersonAddr(null);
		
	}
	
	
	public void addrDeleteList(PersonAddressBean bean){
		System.out.println("Delete address executed");
//		if(checkAddr == true){
//			bean.setSelected(true);
//		}else{
//			if(checkAddr == false){
//				bean.setSelected(false);
//			}
//			
//		}
		System.out.println("Selected:" + bean.getSelected());
		System.out.println("[[--------------------]]");
		System.out.println("  ||||||||||||||||||||  ");
		System.out.println("[[--------------------]]");
		
	}
	
	public void deleteAddress(){
	
		if (this.getPersonAddrCollection().isEmpty()) {
			System.out.println("Empty List");
		}else{
			
			System.out.println("Elimination Method executed");
			System.out.println("Person Addresses: " + this.getPersonAddrCollection());
			
			Iterator<PersonAddressBean> it = personAddrCollection.iterator();
			
//			PersonAddressBean next = null;
			while(it.hasNext()){
				PersonAddressBean next = it.next();
				System.out.println("Next: " + next);
				System.out.println("Selected: " + next.getSelected());
				if(next.getSelected() == true){
					System.out.println("Next: " + next.getSelected());
					it.remove();
				}
			}

				System.out.println("Elements eliminated");

				System.out.println("------------------------");
											
			
		}
		this.setInitVar(null);
		this.checkAddr = false;
		

	}
	
	// Methods for documents handle ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
	
	public void fillDocList(){
		System.out.println("Filling document list");
		if (this.getPersonAddr() == null){
			System.out.println("Entity null");
		}else{
			
			personDocCollection.add(this.getPersonDoc());
			
			System.out.println(this.getPersonDoc().getDocument());
			System.out.println("------------------------");

		}
		this.checkDoc = false;
		this.setInitVar("S");
		this.setPersonDoc(null);
		
		
		
	}
		
	public void docDeleteList(PersonDocumentBean bean){
		System.out.println("Delete doc executed");
		System.out.println("Selected:" + bean.getSelected());
		System.out.println("[[--------------------]]");
		System.out.println("  ||||||||||||||||||||  ");
		System.out.println("[[--------------------]]");
		
	}
	
	public void deleteDocument(){
	
		if (this.getPersonDocCollection().isEmpty()) {
			System.out.println("Empty List");
		}else{
			
			System.out.println("Elimination Method executed");
			System.out.println("Person Documents: " + this.getPersonDocCollection());
			
			Iterator<PersonDocumentBean> it = personDocCollection.iterator();
			
			while(it.hasNext()){
				PersonDocumentBean next = it.next();
				System.out.println("Next: " + next);
				System.out.println("Next: " + next.getSelected());
				if(next.getSelected() == true){
					System.out.println("Next: " + next.getSelected());
					it.remove();
				}
			}

			System.out.println("Elements eliminated");
			System.out.println("------------------------");
											
			
		}
		this.setInitVar(null);
		this.checkDoc = false;
		

	}
	
	
	// Methods for phones handle ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
	
	public void fillPhoneList(){
		System.out.println("Filling phone list");
		if (this.getPersonPhone() == null){
			System.out.println("Entity null");
		}else{
			personPhoneCollection.add(this.getPersonPhone());
			
			System.out.println(this.getPersonPhone());
			System.out.println(this.getPersonPhoneCollection());
		}
		this.checkPhone = false;
		this.setInitVar("S");
		this.setPersonPhone(null);
		
		
	}
	
	public void phoneDeleteList(PersonPhoneBean bean){
		System.out.println("Delete phone executed");
		System.out.println("Selected:" + bean.getSelected());
		System.out.println("[[--------------------]]");
		System.out.println("  ||||||||||||||||||||  ");
		System.out.println("[[--------------------]]");
		
	}
	
	public void deletePhone(){

		if (this.getPersonPhoneCollection().isEmpty()) {
			System.out.println("Empty List");
		}else{
			
			System.out.println("Elimination Method executed");
			System.out.println("Person Documents: " + personManager.getPersonPhoneCollection());

			
			Iterator<PersonPhoneBean> it = personPhoneCollection.iterator();
			
			while(it.hasNext()){
				PersonPhoneBean next = it.next();
				System.out.println("Next: " + next);
				System.out.println("Next: " + next.getSelected());
				if(next.getSelected() == true){
					System.out.println("Next: " + next.getSelected());
					it.remove();
				}
			}

			System.out.println("Elements eliminated");
			System.out.println("------------------------");
											
			
		}
		this.setInitVar(null);
		this.checkDoc = false;
		

	}
	
	// SAVING, UPDATING AND DELETING METHODS ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
	// Used for data saving process
	
	public void savePersonHeader() throws ParseException{
		try{
			// this.facesMessages.clear();
			
			
			
			PersonBean newPerson = new PersonBean();
			
			this.today = DateAssistant.getCurrentDate();
			
			this.setPersonCod(convert.convertField(this.getPersonManager().getPerson().getCod()));
			
			if(this.getPersonCod() == null){
				System.out.println("Codigo de persona nulo");
			}else{
				if(this.getPersonEnt() == 0){
					System.out.println("id de empresa nulo");
				}else{
					System.out.println("Codigo persona: " + this.getPersonCod() + " - Empresa: " + this.getPersonEnt());
				}
			}
			
			if (this.getPerson() == null) {
				System.out.println("Person Entity is null");
				throw new CommonException("Persona no existe");
			}
			
			
			// Setting field values
			
			newPerson.setCod(convert.convertField(this.getPersonManager().getPerson().getCod()));
			newPerson.setIdEnt(new Long(1));
			newPerson.setIsJur(this.getPersonManager().getPerson().getIsJur());
			newPerson.setName(convert.convertField(this.getPersonManager().getPerson().getName()));
			newPerson.setNameFant(convert.convertField(this.getPersonManager().getPerson().getNameFant()));
			newPerson.setRuc(convert.convertField(this.getPersonManager().getPerson().getRuc()));
			newPerson.setSex(convert.convertField(this.getPersonManager().getPerson().getSex()));
			newPerson.setSector(this.getPersonManager().getPerson().getSectorData().getId());
			newPerson.setStatus(this.getPersonManager().getPerson().getStatus());
			newPerson.setStartDate(this.today);
			newPerson.setUserIns(user.getId());
			
			
			// Sending Bean values trough service for saving
			prSrv.saveNewPerson(newPerson);
			
			
		} catch (CommonException e) {
//						this.facesMessages.add(Severity.ERROR, e.getMessage());
			System.out.println("NO SE PUDO INSERTAR LA CABECERA. " + e.getMessage());
			FacesMessages.instance().add("NO SE PUDO INSERTAR LA CABECERA. " + e.getMessage());
			log.error(e);
		} 
	}
	
	public void savePersonDetails(){
		try {
			int i;
			System.out.println("CODIGOOOOOO: " + this.getPersonCod());
			// Retrieving the header id
			if(this.prSrv.getIdPerson(this.getPersonCod()) ==  null){
				System.out.println("Get id method pointing to null");
			}else{
				this.setPersonId(this.prSrv.getIdPerson(this.getPersonCod()));
			}
			
			
			
			// Printing the header id in the screen 
			System.out.println("ID CABECERA: " + this.getPersonId());
			
			// Verify if the header id is null, if not, process the details.
			if(this.getPersonId() == null){
				
				System.out.println("ID DE CABECERA NULO");
				
			}else{
				
				PersonAddressBean newAddress = new PersonAddressBean();
				PersonDocumentBean newDoc = new PersonDocumentBean();
				PersonPhoneBean newPhone = new PersonPhoneBean();
				
				if(personAddrCollection == null || personAddrCollection.isEmpty()){
					
					System.out.println("Lista de direcciones a agregar vacia");
					
				}else{
					Iterator<PersonAddressBean> it1 = personAddrCollection.iterator();
					while(it1.hasNext()){
							// capturing the next element
							PersonAddressBean nextAddr = it1.next();
							
							// printing values for proof
							System.out.println(nextAddr.getAddress());
							System.out.println(nextAddr.getIdAddressType());
							
							// setting bean values
							newAddress.setIdPerson(this.getPersonId());
							newAddress.setIdAddressType(nextAddr.getAddType().getId());
							newAddress.setAddress(nextAddr.getAddress());
							newAddress.setStatus(nextAddr.getStatus());
							newAddress.setIsDefault(nextAddr.getIsDefault());
							
							// saving trough service
							prSrv.savePersonAddress(newAddress);
						
					}
					
				}
				
				if(personDocCollection == null || personDocCollection.isEmpty()){
					
					System.out.println("Lista de documentos a agregar vacia");
					
				}else{
					
					Iterator<PersonDocumentBean> it2 = personDocCollection.iterator();
					while(it2.hasNext()){
						
						// capturing the next element
						PersonDocumentBean nextDoc = it2.next();
						
						// setting bean values
						newDoc.setIdPerson(this.getPersonId());
						newDoc.setIdDocumentType(nextDoc.getDocType().getId());
						newDoc.setIdCountry(nextDoc.getCountryData().getId());
						newDoc.setDocument(nextDoc.getDocument());
						newDoc.setStatus(nextDoc.getStatus());
						newDoc.setIsDefault(nextDoc.getIsDefault());
						
						// saving trough service
						prSrv.savePersonDoc(newDoc);
					}
					
				}
				
				if(personPhoneCollection == null || personPhoneCollection.isEmpty()){
					
					System.out.println("Lista de telefonos a agregar vacia");
					
				}else{
					
					Iterator<PersonPhoneBean> it3 = personPhoneCollection.iterator();
					while(it3.hasNext()){
						
						// capturing the next element
						PersonPhoneBean nextPhone = it3.next();
						
						// setting bean values
						newPhone.setIdPerson(this.getPersonId());
						newPhone.setIdPhoneType(nextPhone.getPhoneType().getId());
						newPhone.setPhone(nextPhone.getPhone());
						newPhone.setStatus(nextPhone.getStatus());
						newPhone.setIsDefault(nextPhone.getIsDefault());
						
						// saving trough service
						prSrv.savePersonPhone(newPhone);
					}
					
				}
				FacesMessages.instance().add("Persona registrada con exito");
				
			}
			
			
		} catch (CommonException e) {
			// this.facesMessages.add(Severity.ERROR, e.getMessage());
			System.out.println("NO SE PUDO INSERTAR EL DETALLE. " + e.getMessage());
			FacesMessages.instance().add("NO SE PUDO INSERTAR EL DETALLE. " + e.getMessage());
			log.error(e);
		}finally{
			personManager = null;
			person = null;
			personAddr = null;
			personDoc = null;
			personPhone = null;
		}
	}
	
	public String saveNewData() throws ParseException, CommonException {
		// Inserting the header
		this.savePersonHeader();
		
		// Inserting the Details
		this.savePersonDetails();
		
		
		
		// Setting Initialization VAR
		this.setInitVar("S");
		this.cleanData();
//		this.initData();
		return null;
		
	}
	
	
	// METHODS FOR UPDATE PERSON OPERATION --------------------]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]	

	// SEARCH OPERATIONS ------------------------------------------------------------------------
	
	public void searchPerson(PersonBean bean) throws CommonException{
		try {
			// Filter 1
			if(bean.getCod() != null){
				bean.setCod(convert.convertField(bean.getCod()));
			}else{
				bean.setCod(null);
			}
			
			// Filter 2
			if(bean.getCod() != null){
				bean.setName(convert.convertField(bean.getName()));
			}else{
				bean.setCod(null);
			}
			
			// Filter 3
			if(bean.getCod() != null){
				bean.setRuc(convert.convertField(bean.getRuc()));
			}else{
				bean.setCod(null);
			}

			System.out.println("codigo: " + bean.getCod());
			System.out.println("bean: " + this.person);
			this.setPersonSearch(prSrv.getPersonSearch(bean));
			
		} catch (CommonException e) {
			e.printStackTrace();
		}finally{
			this.setPerson(null);
			this.setInitVar("S");
//			this.initData();
		}
		
	}
	
	public void searchAddress(PersonBean bean) throws CommonException{
		try {
					
			System.out.println("Address Person: " + bean.getCod());
			System.out.println("bean: " + bean);
			this.setPersonAddrSearch(prSrv.getPersonsAddress(this.getPersonId(bean.getCod())));
			
		} catch (CommonException e) {
			e.printStackTrace();
		}finally{
			this.setPersonUpd(bean);
			this.person = null;
			this.setInitVar("S");
//			this.initData();
		}
		
	}
	
	public void searchDocument(PersonBean bean) throws CommonException{
		try {
			System.out.println("Address Person: " + bean.getCod());
			this.setPersonDocSearch(prSrv.getPersonsDoc(this.getPersonId(bean.getCod())));
			
		} catch (CommonException e) {
			e.printStackTrace();
		}finally{
			this.setPersonUpd(bean);
			this.person = null;
			this.setInitVar("S");
//			this.initData();
		}
		
	}
	
	public void searchPhone(PersonBean bean) throws CommonException{
		try {
			System.out.println("Address Person: " + bean.getCod());
			this.setPersonPhoneSearch(prSrv.getPersonsPhone(this.getPersonId(bean.getCod())));
			
		} catch (CommonException e) {
			e.printStackTrace();
		}finally{
			this.setPersonUpd(bean);
			this.person = null;
			this.setInitVar("S");
//			this.initData();
		}
		
	}
	
	
	// ADD DATA OPERATIONS ------------------------------------------------------------------------
	// [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[------------------------]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
	

	public void addrToAdd(){
		System.out.println("Filling address list");
		if (this.getAddrToAdd() == null){
			System.out.println("Entity null");
		}else{
			
			personAddrToAdd.add(this.getAddrToAdd());
			
			System.out.println(this.getAddrToAdd().getAddress());
			System.out.println("PER DATA: " + this.getPersonToAdd());
			System.out.println("PER ID: " + this.getPersonToAdd().getId());
			System.out.println("------------------------");
		}
		this.setInitVar("S");
		this.setAddrToAdd(null);
		
	}
	
	public void addrSelected(PersonAddressBean bean){
		System.out.println("Address Selected");
		System.out.println("Selected:" + bean.getSelected());
		System.out.println("[[--------------------]]");
		System.out.println("  ||||||||||||||||||||  ");
		System.out.println("[[--------------------]]");
		
	}
	
	public void addrToAddDel(){
	
		if (this.getPersonAddrToAdd().isEmpty()) {
			System.out.println("Empty List");
		}else{
			
			System.out.println("Elimination Method executed");
			System.out.println("Person Addresses: " + this.getPersonAddrToAdd());
			
			Iterator<PersonAddressBean> it = personAddrToAdd.iterator();
			
			while(it.hasNext()){
				PersonAddressBean next = it.next();
				System.out.println("Next: " + next);
				System.out.println("Selected: " + next.getSelected());
				if(next.getSelected() == true){
					System.out.println("Next: " + next.getSelected());
					it.remove();
				}
			}

			System.out.println("Elements eliminated");
			System.out.println("------------------------");
											
			
		}
		this.setInitVar(null);
		

	}
	
	public void docToAdd(){
		System.out.println("Filling Doc list");
		if (this.getDocToAdd() == null){
			System.out.println("Entity null");
		}else{
			
			personDocToAdd.add(this.getDocToAdd());
			
			System.out.println(this.getDocToAdd().getDocument());
			System.out.println("------------------------");
		}
		this.setInitVar("S");
		this.setDocToAdd(null);
		
	}
	
	public void docSelected(PersonDocumentBean bean){
		System.out.println("Doc Selected");
		System.out.println("Selected:" + bean.getSelected());
		System.out.println("[[--------------------]]");
		System.out.println("  ||||||||||||||||||||  ");
		System.out.println("[[--------------------]]");
		
	}
	
	public void docToAddDel(){
	
		if (this.getPersonDocToAdd().isEmpty()) {
			System.out.println("Empty List");
		}else{
			
			System.out.println("Elimination Method executed");
			System.out.println("Person Docs: " + this.getPersonDocToAdd());
			
			Iterator<PersonDocumentBean> it = personDocToAdd.iterator();
			
			while(it.hasNext()){
				PersonDocumentBean next = it.next();
				System.out.println("Next: " + next);
				System.out.println("Selected: " + next.getSelected());
				if(next.getSelected() == true){
					System.out.println("Next: " + next.getSelected());
					it.remove();
				}
			}

			System.out.println("Elements eliminated");
			System.out.println("------------------------");
											
			
		}
		this.setInitVar(null);
		

	}
	
	public void phoneToAdd(){
		System.out.println("Filling Phone list");
		if (this.getDocToAdd() == null){
			System.out.println("Entity null");
		}else{
			
			personPhoneToAdd.add(this.getPhoneToAdd());
			
			System.out.println(this.getPhoneToAdd().getPhone());
			System.out.println("------------------------");
		}
		this.setInitVar("S");
		this.setPhoneToAdd(null);
		
	}
	
	public void phoneSelected(PersonPhoneBean bean){
		System.out.println("Phone Selected");
		System.out.println("Selected:" + bean.getSelected());
		System.out.println("[[--------------------]]");
		System.out.println("  ||||||||||||||||||||  ");
		System.out.println("[[--------------------]]");
		
	}
	
	public void phoneToAddDel(){
	
		if (this.getPersonPhoneToAdd().isEmpty()) {
			System.out.println("Empty List");
		}else{
			
			System.out.println("Elimination Method executed");
			System.out.println("Person Phones: " + this.getPersonPhoneToAdd());
			
			Iterator<PersonPhoneBean> it = personPhoneToAdd.iterator();
			
			while(it.hasNext()){
				PersonPhoneBean next = it.next();
				System.out.println("Next: " + next);
				System.out.println("Selected: " + next.getSelected());
				if(next.getSelected() == true){
					System.out.println("Next: " + next.getSelected());
					it.remove();
				}
			}

			System.out.println("Elements eliminated");
			System.out.println("------------------------");
											
			
		}
		this.setInitVar(null);
		

	}
	
	public void addPersonDetails(){
		try {
			int i;
			// Retrieving the header id
			if(this.getPersonToAdd() == null || this.getPersonToAdd().getId() == 0){
				System.out.println("Person is null");
			}else{
				System.out.println("Person Data is Correct");
			}

			if((Long)this.getPersonToAdd().getId() == null){
				
				System.out.println("Person Id is null");
			}else{
				if(personAddrToAdd.isEmpty() &&  personDocToAdd.isEmpty() && personPhoneToAdd.isEmpty()){
					
					FacesMessages.instance().add("Debe ingresar datos para agregar a personas");
				
				}else{
					System.out.println("Person Id: " + this.getPersonToAdd().getId());
					PersonAddressBean newAddress = new PersonAddressBean();
					PersonDocumentBean newDoc = new PersonDocumentBean();
					PersonPhoneBean newPhone = new PersonPhoneBean();
					
					if(personAddrToAdd == null || personAddrToAdd.isEmpty()){
						
						System.out.println("Lista de direcciones a agregar vacia");
						
					}else{
						Iterator<PersonAddressBean> it1 = personAddrToAdd.iterator();
						while(it1.hasNext()){
								// capturing the next element
								PersonAddressBean nextAddr = it1.next();
								
								// printing values for proof
								System.out.println(nextAddr.getAddress());
								System.out.println(nextAddr.getAddType().getId());
								
								// setting bean values
								newAddress.setIdPerson(this.getPersonToAdd().getId());
								newAddress.setIdAddressType(nextAddr.getAddType().getId());
								newAddress.setAddress(nextAddr.getAddress());
								newAddress.setStatus(nextAddr.getStatus());
								newAddress.setIsDefault(nextAddr.getIsDefault());
								
								// saving trough service
								prSrv.savePersonAddress(newAddress);
							
						}
						
					}
					
					if(personDocToAdd == null || personDocToAdd.isEmpty()){
						
						System.out.println("Lista de documentos a agregar vacia");
						
					}else{
						
						Iterator<PersonDocumentBean> it2 = personDocToAdd.iterator();
						while(it2.hasNext()){
							
							// capturing the next element
							PersonDocumentBean nextDoc = it2.next();
							
							// setting bean values
							newDoc.setIdPerson(this.getPersonToAdd().getId());
							newDoc.setIdDocumentType(nextDoc.getDocType().getId());
							newDoc.setIdCountry(nextDoc.getCountryData().getId());
							newDoc.setDocument(nextDoc.getDocument());
							newDoc.setStatus(nextDoc.getStatus());
							newDoc.setIsDefault(nextDoc.getIsDefault());
							
							// saving trough service
							prSrv.savePersonDoc(newDoc);
						}
						
					}
					
					if(personPhoneToAdd == null || personPhoneToAdd.isEmpty()){
						
						System.out.println("Lista de telefonos a agregar vacia");
						
					}else{
						
						Iterator<PersonPhoneBean> it3 = personPhoneToAdd.iterator();
						while(it3.hasNext()){
							
							// capturing the next element
							PersonPhoneBean nextPhone = it3.next();
							
							// setting bean values
							newPhone.setIdPerson(this.getPersonToAdd().getId());
							newPhone.setIdPhoneType(nextPhone.getPhoneType().getId());
							newPhone.setPhone(nextPhone.getPhone());
							newPhone.setStatus(nextPhone.getStatus());
							newPhone.setIsDefault(nextPhone.getIsDefault());
							
							// saving trough service
							prSrv.savePersonPhone(newPhone);
						}
						
					}
					
					FacesMessages.instance().add("Datos agregados con exito");
				}
			}
			
			
			
		} catch (CommonException e) {
			// this.facesMessages.add(Severity.ERROR, e.getMessage());
			System.out.println("NO SE PUDO INSERTAR EL DETALLE. " + e.getMessage());
			FacesMessages.instance().add("NO SE PUDO INSERTAR EL DETALLE. " + e.getMessage());
			log.error(e);
		}finally{
			this.cleanData();
			this.setInitVar("S");
		}
	}
	
	// [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[------------------------]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
	// Used to load a grid using a collection
	private void loadGrid() {
		try {
			this.setAllPersons(prSrv.getAllPersons());
			
		} catch (CommonException e) {
			e.printStackTrace();
		}
	}
	
	
	// DELETE OPERATIONS ------------------------------------------------------------------------
	public void personToDelete(Long id){
		System.out.println(this.getAllPersons());
		for (PersonBean bean: this.getAllPersons()){
			if (bean.getId() == id) {
				try {
					
					prSrv.deletePersonById(bean.getId());
					
				} catch (Exception e) {
//					this.facesMessages.add(Severity.ERROR, e.getMessage());
					System.out.println("NO SE PUDO BORRAR EL REGISTRO. " + e.getMessage());
					FacesMessages.instance().add("NO SE PUDO BORRAR EL REGISTRO. " + e.getMessage());
					log.error(e);
				}
			}
			
		}
		this.setInitVar("S");
	}
	
	public void addressToDelete(Long id){
		System.out.println(this.getAllPersonAddress());
		for (PersonAddressBean bean: this.getAllPersonAddress()){
			if (bean.getId() == id) {
				try {
					
					prSrv.deletePersonAddrById(bean.getId());
					
				} catch (Exception e) {
//					this.facesMessages.add(Severity.ERROR, e.getMessage());
					System.out.println("NO SE PUDO BORRAR EL REGISTRO. " + e.getMessage());
					FacesMessages.instance().add("NO SE PUDO BORRAR EL REGISTRO. " + e.getMessage());
					log.error(e);
				}
			}
			
		}
		this.setInitVar("S");
	}
	
	public void docToDelete(Long id){
		System.out.println(this.getAllPersonDoc());
		for (PersonDocumentBean bean: this.getAllPersonDoc()){
			if (bean.getId() == id) {
				try {
					
					prSrv.deletePersonDocById(bean.getId());
					
				} catch (Exception e) {
//					this.facesMessages.add(Severity.ERROR, e.getMessage());
					System.out.println("NO SE PUDO BORRAR EL REGISTRO. " + e.getMessage());
					FacesMessages.instance().add("NO SE PUDO BORRAR EL REGISTRO. " + e.getMessage());
					log.error(e);
				}
			}
			
		}
		this.setInitVar("S");
	}
	
	public void phoneToDelete(Long id){
		System.out.println(this.getAllPersonPhone());
		for (PersonPhoneBean bean: this.getAllPersonPhone()){
			if (bean.getId() == id) {
				try {
					
					prSrv.deletePersonPhoneById(bean.getId());
					
				} catch (Exception e) {
//					this.facesMessages.add(Severity.ERROR, e.getMessage());
					System.out.println("NO SE PUDO BORRAR EL REGISTRO. " + e.getMessage());
					FacesMessages.instance().add("NO SE PUDO BORRAR EL REGISTRO. " + e.getMessage());
					log.error(e);
				}
			}
			
		}
		this.setInitVar("S");
	}
	
	// UPDATE OPERATIONS ------------------------------------------------------------------------
	public void personToEdit(Long id) throws CommonException{
		System.out.println(this.getAllPersons());
		System.out.println("id = " + id.toString());
		for (PersonBean bean : this.getAllPersons()) {
			if(bean.getId() == id){
//				bean.setSectorData(rnSrv.getDetById(bean.getSector()));
				this.setEditPerson(bean);
				System.out.println(this.getEditPerson());
				return;
			}			
		}
		
	}
	
	public void addressToEdit(Long id) throws CommonException{
		System.out.println(this.getAllPersonAddress());
		System.out.println("id = " + id.toString());
		for (PersonAddressBean bean : this.getAllPersonAddress()) {
			if(bean.getId() == id){
				this.setEditAddr(bean);
//				this.getEditAddr().setAddType(rnSrv.getDetById(this.getEditAddr().getIdAddressType()));
				System.out.println(this.getEditAddr());
				return;
			}			
		}
		
	}
	
	public void docToEdit(Long id) throws CommonException{
		System.out.println(this.getAllPersonDoc());
		System.out.println("id = " + id.toString());
		for (PersonDocumentBean bean : this.getAllPersonDoc()) {
			if(bean.getId() == id){
				System.out.println(bean.getIdCountry());
				WithinHolder aid = (WithinHolder)Component.getInstance(
						WithinHolder.class, true);
				if (aid == null) {
					return;
				}
				CountryBean cntBean = aid.countryData(cnSrv.getDescCounrty(bean.getIdCountry()));
				bean.setCountryData(cntBean);
//				bean.setDocType(rnSrv.getDetById(bean.getIdDocumentType()));
				this.setEditDoc(bean);
				System.out.println(this.getEditDoc());
				System.out.println("country desc: " + bean.getCountryData().getDescrip());
				return;
			}			
		}
		
	}
	
	public void phoneToEdit(Long id) throws CommonException{
		System.out.println(this.getAllPersonPhone());
		System.out.println("id = " + id.toString());
		for (PersonPhoneBean bean : this.getAllPersonPhone()) {
			if(bean.getId() == id){
//				bean.setPhoneType(rnSrv.getDetById(bean.getIdPhoneType()));
				this.setEditPhone(bean);
				System.out.println(this.getEditPhone());
				return;
			}			
		}
		
	}
	
	public Long getPersonId(String cod) throws CommonException{
		Long id = prSrv.getIdPerson(cod);
		return id;
	}
	
	
	public void personUpd(){
		try {
			PersonServices admSrv = new PersonServices(this.sqlMap.getConfig());
			admSrv.updatePerson(this.getEditPerson());
			this.searchPerson(this.getEditPerson());
			FacesMessages.instance().add("Persona actualizada con exito");
		} catch (CommonException e) {
//			this.facesMessages.add(Severity.ERROR, e.getMessage());
			System.out.println("NO SE PUDO ACTUALIZAR EL REG. " + e.getMessage());
			FacesMessages.instance().add("NO SE PUDO ACTUALIZAR EL REG. " + e.getMessage());
			log.error(e);
		}
	}
	
	public void addressUpd(){
		try {
			this.getEditAddr().setIdAddressType(this.getEditAddr().getAddType().getId());
			prSrv.updateAddress(this.getEditAddr());
			this.searchAddress(this.getPersonUpd());
			FacesMessages.instance().add("Direccion actualizada con exito");
		} catch (CommonException e) {
//			this.facesMessages.add(Severity.ERROR, e.getMessage());
			System.out.println("NO SE PUDO ACTUALIZAR EL REG. " + e.getMessage());
			FacesMessages.instance().add("NO SE PUDO ACTUALIZAR EL REG. " + e.getMessage());
			log.error(e);
		}
	}
	
	public void docUpd(){
		try {
			this.editDoc.setIdCountry(this.cnSrv.getIdCounrty(this.convert.getCountryCod(this.getEditDoc().getCountryData())));
			this.getEditDoc().setIdDocumentType(this.getEditDoc().getDocType().getId());
			prSrv.updateDoc(this.getEditDoc());
			this.searchDocument(this.getPersonUpd());
			FacesMessages.instance().add("Documento actualizado con exito");
		} catch (CommonException e) {
//			this.facesMessages.add(Severity.ERROR, e.getMessage());
			System.out.println("NO SE PUDO ACTUALIZAR EL REG. " + e.getMessage());
			FacesMessages.instance().add("NO SE PUDO ACTUALIZAR EL REG. " + e.getMessage());
			log.error(e);
		}
	}
	
	public void phoneUpd(){
		try {
			this.getEditPhone().setIdPhoneType(this.getEditPhone().getPhoneType().getId());
			prSrv.updatePhone(this.getEditPhone());
			this.searchPhone(this.getPersonUpd());
			FacesMessages.instance().add("Telefono actualizado con exito");
		} catch (CommonException e) {
//			this.facesMessages.add(Severity.ERROR, e.getMessage());
			System.out.println("NO SE PUDO ACTUALIZAR EL REG. " + e.getMessage());
			FacesMessages.instance().add("NO SE PUDO ACTUALIZAR EL REG. " + e.getMessage());
			log.error(e);
		}
	}

	// Used to cancel
	public String cancelData() throws CommonException {
//		this.facesMessages.clear();
		this.setInitVar("S");
		this.cleanData();
		this.initData();
		return null;
	}
	
	// GETTERS AND SETTERS

	public FacesMessages getFacesMessages() {
		return facesMessages;
	}

	public void setFacesMessages(FacesMessages facesMessages) {
		this.facesMessages = facesMessages;
	}

	public Log getLog() {
		return log;
	}

	public void setLog(Log log) {
		this.log = log;
	}

	public ServiceSqlMap getSqlMap() {
		return sqlMap;
	}

	public void setSqlMap(ServiceSqlMap sqlMap) {
		this.sqlMap = sqlMap;
	}
	
	public String getInitVar() {
		return initVar;
	}

	public void setInitVar(String initVar) {
		this.initVar = initVar;
	}

	public DateAssistant getDateAssist() {
		return dateAssist;
	}

	public void setDateAssist(DateAssistant dateAssist) {
		this.dateAssist = dateAssist;
	}

	public PersonBean getPerson() {
		return person;
	}

	public void setPerson(PersonBean person) {
		this.person = person;
	}

	public PersonBean getPersonUpd() {
		return personUpd;
	}

	public void setPersonUpd(PersonBean personUpd) {
		this.personUpd = personUpd;
	}

	public PersonManagerBean getPersonManager() {
		return personManager;
	}

	public void setPersonManager(PersonManagerBean personManager) {
		this.personManager = personManager;
	}

	public PersonAddressBean getPersonAddr() {
		return personAddr;
	}

	public void setPersonAddr(PersonAddressBean personAddr) {
		this.personAddr = personAddr;
	}

	public PersonDocumentBean getPersonDoc() {
		return personDoc;
	}

	public void setPersonDoc(PersonDocumentBean personDoc) {
		this.personDoc = personDoc;
	}

	public PersonPhoneBean getPersonPhone() {
		return personPhone;
	}

	public void setPersonPhone(PersonPhoneBean personPhone) {
		this.personPhone = personPhone;
	}

	public PersonBean getEditPerson() {
		return editPerson;
	}

	public void setEditPerson(PersonBean editPerson) {
		this.editPerson = editPerson;
	}

	public PersonAddressBean getEditAddr() {
		return editAddr;
	}

	public void setEditAddr(PersonAddressBean editAddr) {
		this.editAddr = editAddr;
	}

	public PersonDocumentBean getEditDoc() {
		return editDoc;
	}

	public void setEditDoc(PersonDocumentBean editDoc) {
		this.editDoc = editDoc;
	}

	public PersonPhoneBean getEditPhone() {
		return editPhone;
	}

	public void setEditPhone(PersonPhoneBean editPhone) {
		this.editPhone = editPhone;
	}

	public Collection<PersonBean> getAllPersons() {
		return allPersons;
	}

	public void setAllPersons(Collection<PersonBean> allPersons) {
		this.allPersons = allPersons;
	}

	public Collection<PersonAddressBean> getAllPersonAddress() {
		return allPersonAddress;
	}

	public void setAllPersonAddress(Collection<PersonAddressBean> allPersonAddress) {
		this.allPersonAddress = allPersonAddress;
	}

	public Collection<PersonDocumentBean> getAllPersonDoc() {
		return allPersonDoc;
	}

	public void setAllPersonDoc(Collection<PersonDocumentBean> allPersonDoc) {
		this.allPersonDoc = allPersonDoc;
	}

	public Collection<PersonPhoneBean> getAllPersonPhone() {
		return allPersonPhone;
	}

	public void setAllPersonPhone(Collection<PersonPhoneBean> allPersonPhone) {
		this.allPersonPhone = allPersonPhone;
	}

	public List<PersonAddressBean> getPersonAddrCollection() {
		return personAddrCollection;
	}

	public void setPersonAddrCollection(List<PersonAddressBean> personAddrCollection) {
		this.personAddrCollection = personAddrCollection;
	}

	public List<PersonDocumentBean> getPersonDocCollection() {
		return personDocCollection;
	}

	public void setPersonDocCollection(List<PersonDocumentBean> personDocCollection) {
		this.personDocCollection = personDocCollection;
	}

	public List<PersonPhoneBean> getPersonPhoneCollection() {
		return personPhoneCollection;
	}

	public void setPersonPhoneCollection(List<PersonPhoneBean> personPhoneCollection) {
		this.personPhoneCollection = personPhoneCollection;
	}

	public List<PersonBean> getPersonSearch() {
		return personSearch;
	}

	public void setPersonSearch(List<PersonBean> personSearch) {
		this.personSearch = personSearch;
	}

	public List<PersonAddressBean> getPersonAddrSearch() {
		return personAddrSearch;
	}

	public void setPersonAddrSearch(List<PersonAddressBean> personAddrSearch) {
		this.personAddrSearch = personAddrSearch;
	}

	public List<PersonDocumentBean> getPersonDocSearch() {
		return personDocSearch;
	}

	public void setPersonDocSearch(List<PersonDocumentBean> personDocSearch) {
		this.personDocSearch = personDocSearch;
	}

	public List<PersonPhoneBean> getPersonPhoneSearch() {
		return personPhoneSearch;
	}

	public void setPersonPhoneSearch(List<PersonPhoneBean> personPhoneSearch) {
		this.personPhoneSearch = personPhoneSearch;
	}

	public Long getPersonId() {
		return personId;
	}

	public void setPersonId(Long personId) {
		this.personId = personId;
	}

	public long getPersonEnt() {
		return personEnt;
	}

	public void setPersonEnt(long personEnt) {
		this.personEnt = personEnt;
	}

	public String getPersonCod() {
		return personCod;
	}

	public void setPersonCod(String personCod) {
		this.personCod = personCod;
	}

	public PersonBean getPersonName() {
		return personName;
	}

	public void setPersonName(PersonBean personName) {
		this.personName = personName;
	}

	public boolean isCheckAddr() {
		return checkAddr;
	}

	public void setCheckAddr(boolean checkAddr) {
		this.checkAddr = checkAddr;
	}

	public boolean isCheckDoc() {
		return checkDoc;
	}

	public void setCheckDoc(boolean checkDoc) {
		this.checkDoc = checkDoc;
	}

	public boolean isCheckPhone() {
		return checkPhone;
	}

	public void setCheckPhone(boolean checkPhone) {
		this.checkPhone = checkPhone;
	}

	public String getOperation() {
		return operation;
	}

	public void setOperation(String operation) {
		this.operation = operation;
	}

	public String getSelectedTab() {
		return selectedTab;
	}

	public void setSelectedTab(String selectedTab) {
		this.selectedTab = selectedTab;
	}

	public String getUpdTab() {
		return updTab;
	}

	public void setUpdTab(String updTab) {
		this.updTab = updTab;
	}

	public String getSelectedTabUpd() {
		return selectedTabUpd;
	}

	public void setSelectedTabUpd(String selectedTabUpd) {
		this.selectedTabUpd = selectedTabUpd;
	}

	public PersonBean getPersonToAdd() {
		return personToAdd;
	}

	public void setPersonToAdd(PersonBean personToAdd) {
		this.personToAdd = personToAdd;
	}

	public PersonAddressBean getAddrToAdd() {
		return addrToAdd;
	}

	public void setAddrToAdd(PersonAddressBean addrToAdd) {
		this.addrToAdd = addrToAdd;
	}

	public PersonDocumentBean getDocToAdd() {
		return docToAdd;
	}

	public void setDocToAdd(PersonDocumentBean docToAdd) {
		this.docToAdd = docToAdd;
	}

	public PersonPhoneBean getPhoneToAdd() {
		return phoneToAdd;
	}

	public void setPhoneToAdd(PersonPhoneBean phoneToAdd) {
		this.phoneToAdd = phoneToAdd;
	}

	public List<PersonAddressBean> getPersonAddrToAdd() {
		return personAddrToAdd;
	}

	public void setPersonAddrToAdd(List<PersonAddressBean> personAddrToAdd) {
		this.personAddrToAdd = personAddrToAdd;
	}

	public List<PersonDocumentBean> getPersonDocToAdd() {
		return personDocToAdd;
	}

	public void setPersonDocToAdd(List<PersonDocumentBean> personDocToAdd) {
		this.personDocToAdd = personDocToAdd;
	}

	public List<PersonPhoneBean> getPersonPhoneToAdd() {
		return personPhoneToAdd;
	}

	public void setPersonPhoneToAdd(List<PersonPhoneBean> personPhoneToAdd) {
		this.personPhoneToAdd = personPhoneToAdd;
	}

	public UsersBean getUser() {
		return user;
	}

	public void setUser(UsersBean user) {
		this.user = user;
	}

	public Long getAddrTypeId() {
		return addrTypeId;
	}

	public void setAddrTypeId(Long addrTypeId) {
		this.addrTypeId = addrTypeId;
	}

	public Long getDocTypeId() {
		return docTypeId;
	}

	public void setDocTypeId(Long docTypeId) {
		this.docTypeId = docTypeId;
	}

	public Long getPhoneTypeId() {
		return phoneTypeId;
	}

	public void setPhoneTypeId(Long phoneTypeId) {
		this.phoneTypeId = phoneTypeId;
	}

	public Long getSectorId() {
		return sectorId;
	}

	public void setSectorId(Long sectorId) {
		this.sectorId = sectorId;
	}

	public String getAddrType() {
		return addrType;
	}

	public void setAddrType(String addrType) {
		this.addrType = addrType;
	}

	public String getDocType() {
		return docType;
	}

	public void setDocType(String docType) {
		this.docType = docType;
	}

	public String getPhoneType() {
		return phoneType;
	}

	public void setPhoneType(String phoneType) {
		this.phoneType = phoneType;
	}

	public String getSectorEco() {
		return sectorEco;
	}

	public void setSectorEco(String sectorEco) {
		this.sectorEco = sectorEco;
	}



		
	

}
